import java.util.ArrayList;

public class Stack<T> {
    private ArrayList<T> elements;

    /** Creates a new stack of size 0 */
    public Stack() {
        elements = new ArrayList<T>();
    }

    /** Creates a new stack with the specified initial size */
    public Stack(int size) {
        elements = new ArrayList<T>(size);
    }

    /** Pushes a new element onto the top of the stack */
    public void push(T item) {
        elements.add(item);
    }

    /**
     * Removes the top-most element from the stack.
     *
     * @return the popped element if the stack is not empty, {@code null} otherwise.
     */
    public T pop() {
        if (elements.size() >= 1)
            return elements.remove(elements.size() - 1);
        else
            return null;
    }

    /** @return the top-most element of this stack without removing it if not empty, {@code null} otherwise */
    public T top() {
        if (elements.size() >= 1)
            return elements.get(elements.size() - 1);
        else
            return null;
    }

    /** @return true if the stack is empty, false otherwise */
    public boolean isEmpty() {
        return elements.isEmpty();
    }

    /** @return the current size of the stack */
    public int size() {
        return elements.size();
    }
}
